package com.bxait.toymail.coupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.coupon.entity.SeckillSessionEntity;
import com.bxait.toymail.coupon.service.SeckillSessionService;

import javax.annotation.Resource;


/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 秒杀活动场次
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:32:28
 */
@RestController
@RequestMapping("coupon/seckillsession")
public class SeckillSessionController {
    @Resource
    @Qualifier("seckillSessionService")
    private SeckillSessionService seckillSessionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = seckillSessionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SeckillSessionEntity seckillSession = seckillSessionService.getById(id);

        return R.ok().put("seckillSession", seckillSession);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.save(seckillSession);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SeckillSessionEntity seckillSession){
		seckillSessionService.updateById(seckillSession);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		seckillSessionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /*
     * @param 
     * @==============History===============<br/>
     * @Description //   获取最近3天需要上架的商品
     * @Date 2023/4/30 2023/4/30 
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return com.bxait.com.utils.R
     */
    @GetMapping("late3DaySession")
    public R getLate3DaySession(){
        List<SeckillSessionEntity> sessions = seckillSessionService.getLate3DaySession();
        return R.ok().setData(sessions);
    }

}
